package com.charging.business.vo.obj;

import com.alibaba.fastjson2.annotation.JSONField;
import com.charging.business.gantry.EntryFeeCalcResponse;
import lombok.Data;
import org.springframework.stereotype.Component;

/**
 * @author JerryLu
 * @date 2024/9/26 15:47
 * @description OBU计费结果
 */
@Component
@Data
public class EtcFeeInfo {
    /**
     * 总应收金额, 单位：分
     * 必填：是
     */
    @JSONField(ordinal = 0)
    public Integer payFee;

    /**
     * 总优惠金额, 单位：分
     * 必填：是
     */
    @JSONField(ordinal = 1)
    public Integer discountFee;

    /**
     * 总实收金额, 单位：分
     * 必填：是
     */
    @JSONField(ordinal = 2)
    public Integer fee;

    /**
     * 总里程, 里程总数累计
     * 必填：是
     */
    @JSONField(ordinal = 3)
    public Integer feeMileage;

    /**
     * 计费模块输出
     * 必填：是
     * 为最后一段行程的收费信息
     */
    @JSONField(ordinal = 4)
    public FeeInfo feeInfo = new FeeInfo();

    /**
     * 多省标识
     * 自定义字段
     * true - 为多省
     * false - 为单省
     */
//    @JSONField(ordinal = 5, serialize = false, deserialize = false)
//    public boolean zMultiProvinces = false;

    /**
     * 过省数量
     * 自定义字段
     */
//    @JSONField(ordinal = 6, serialize = false, deserialize = false)
//    public Integer zProvinceCount = 0;

    public void setInfo(EntryFeeCalcResponse rsp) {
        feeInfo.rateVersion = rsp.getParamVersion();                //计费模块和计费参数版本号
        feeInfo.feeVehicleType = rsp.getFeeVehicleType();           //计费车型
        feeInfo.feeMileage = rsp.getFeeMileage();                   //拟合计费里程
        feeInfo.payFee = rsp.getPayFee();                           //拟合应收
        feeInfo.realFee = rsp.getRealFee();                         //拟合实收
        feeInfo.cardFee = rsp.getCardFee();                         //ETC最终卡面扣款金额（复合消费金额)
        feeInfo.discountFee = rsp.getDiscountFee();                 //拟合优惠
        feeInfo.tollIntervalIDs = rsp.getTollInterValIds();         //拟合收费单元组
        feeInfo.payFeeGroup = rsp.getPayFeeGroup();                 //拟合应收组
        feeInfo.feeGroup = rsp.getFeeGroup();                       //拟合实收组
        feeInfo.discountFeeGroup = rsp.getDiscountFeeGroup();       //拟合优惠组
        feeInfo.feeSpare2 = rsp.getFeeSpare2();                     //本省累计里程
        feeInfo.feeSpare1 = rsp.getFeeSpare1();                     //本省累计应收
        feeInfo.feeProvSumLocal = rsp.getFeeProvSumLocal();         //本省累计实收
        feeInfo.provMinFee = rsp.getProvMinFee();                   //本省最小费
        feeInfo.feeCalcSpecials = rsp.getFeeSpecial();              //计费特情组合
        feeInfo.pathFitFlag = rsp.getFitResult();                   //拟合结果
        feeInfo.feeInfo1 = rsp.getFeeInfo1();
        feeInfo.feeInfo2 = rsp.getFeeInfo2();
        feeInfo.feeInfo3 = rsp.getFeeInfo3();
        feeInfo.feeLogMsg = rsp.getFeeLogMsg();
        feeInfo.feeSpare3 = rsp.getFeeSpare3();
        feeInfo.feeProvBeginHexFit = rsp.getFeeProvBeginHexFit();   //拟合本省入口
        feeInfo.feeProvBeginTimeFit = rsp.getFeeProvBeginTimeFit(); //拟合本省入口时间
        if (rsp.getFitProvFlag() == 0) {
            feeInfo.fitProvFlag = 0;
            feeInfo.gantryPassNumFit = 0;
            feeInfo.gantryPassHexFit = "";
        } else {
            feeInfo.fitProvFlag = rsp.getFitProvFlag();
            feeInfo.gantryPassNumFit = rsp.getGantryPassNumFit();
            feeInfo.gantryPassHexFit = rsp.getGantryPassHexFit();
        }
    }

    /**
     * 绿通、联合收割机免费处理
     * 分省信息保持不变
     */
    @JSONField(serialize = false, deserialize = false)
    public void green() {
        fee = 0;
        discountFee = payFee;
    }

    /**
     * 全免费,清除计费信息
     */
    @JSONField(serialize = false, deserialize = false)
    public void toAllFree() {
        fee = 0;
        discountFee = payFee;

        feeInfo.toFree();
    }

    /**
     * 本省免费,清除本省计费信息<br>
     * 最后一段行程免费
     */
    @JSONField(serialize = false, deserialize = false)
    public void toLocalFree() {
        fee = fee - feeInfo.feeProvSumLocal;
        if (fee < 0) {
            fee = 0;
        }

        discountFee = payFee - fee;

        feeInfo.toFree();
    }
}
